package myJs.user.soft.preprocess

import myJs.cps._
import myJs.myPkg.reactHookForm._
import myJs.tool.Tool
import myJs.tool.Tool._
import myJs.user.soft.preprocess.AllCp.PreprocessT
import shared.Pojo._
import shared.pojo.WorkflowMission._

import scala.collection.SeqMap

import japgolly.scalajs.react.vdom.all._
import japgolly.scalajs.react._
import japgolly.scalajs.react.React.Fragment
import japgolly.scalajs.react.util.EffectCatsEffect._
import myJs.myPkg.Hooks._
import cats.effect._
import myJs.Implicits._
import myJs.Utils._

/** Created by yz on 3/11/2020
  */
object LoessCp extends PreprocessT with LoessSoftT {

  case class Props(
      curI: Int,
      datasChange: List[EachPreprocessData] => SyncIO[Unit],
      datas: List[EachPreprocessData],
      insertModule: String => SyncIO[Unit],
      removeModule: Int => SyncIO[Unit]
  ){
    @inline def render: VdomElement = {
      Component(this)
    }
  }

  val Component = ScalaFnComponent[Props] { props =>
    object FTool {

      def removeModuleF =  {
        props.removeModule(props.curI)
      }

      def insertModule = (moduleName: String) => {
        props.insertModule(moduleName)
      }

    }

    useEffect(
      SyncIO{
        Tool.popover
      }.void,
      List()
    )

    val optionMap = SeqMap("yes" -> messages("yes"))
    val contentStr = messages("execLOESSInfo")

    fieldset(
      paddingRight := "5px", border := "1px solid silver", margin := "0 2px", borderRadius := "4px",
      className := "northbtn myEachSoft",
      MyToolCp.Props(removeModule = FTool.removeModuleF, insertModule = FTool.insertModule).render,
      legend(
        s"${messages(nameStr)}",
        span(
          className := "",
          a(
            `type` := "button",
            className := "selfQuestion",
            title := messages("note"),
            dataContainer:= "body",
            dataToggle:= "popover",
            dataHtml:= "true",
            dataPlacement := "left",
            dataContent :=
              s"""
               |This step require QC samples existing in raw data too.
               |""".stripMargin,
            i(className := "fa fa-question-circle-o")
          )
        )
      ),
      div(
        SelectInlineCp.Props(
          value = "yes",
          label = messages("execLOESS"),
          name = "execLOESS",
          disabled = true,
          optionMap = optionMap,
          questionInfo = contentStr
        ).render
      )
    )

  }

  def cp(
      curI: Int,
      datas: List[EachPreprocessData],
      datasChange: List[EachPreprocessData] => SyncIO[Unit],
      insertModule: String => SyncIO[Unit],
      removeModule: Int => SyncIO[Unit],
      extraData: ExtraData
  ) = {
    LoessCp.Props(
      curI = curI,
      datas = datas,
      datasChange = datasChange,
      insertModule = insertModule,
      removeModule = removeModule
    ).render
  }

}
